package com.treeroot.designMode.Strategy.useFactory;

import com.treeroot.designMode.Strategy.Goods;

/**
 * 封装住策略模式 把每一种策略都归为一个工厂产品
 * @author treeroot
 *
 */
public class Controller {
        public static void main(String[] args) {
            Goods goods = new Goods("手机", 200);
            //获取上下文---->策略的使用者--->构造函数传入工厂对象
            DiscountContext context = new DiscountContext(goods, new EightDiscountFactory());
            System.out.println("原价：" + goods.getPrice() + "元，打折后价格为：" + context.calculateDiscountPrice() + "元");
            //动态地切换算法---->set方法传入工厂对象
            context.setFactory(new FullMinusFactory());
            System.out.println("原价：" + goods.getPrice() + "元，打折后价格为：" + context.calculateDiscountPrice() + "元");
        }

}
